//
//  NewsCustomTableViewCell.m
//  WangI
//
//  Created by dllo on 15/11/24.
//  Copyright © 2015年 WJN. All rights reserved.
//

#import "NewsCustomTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "WYKit.h"
@implementation NewsCustomTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.leftImage];
        [self addSubview:self.titleLabel];
        [self addSubview:self.detailLabel];
        [self addSubview:self.numLabel];
        [_leftImage release];
        [_titleLabel release];
        [_detailLabel release];
        [_numLabel release];
        
        
        
    }
    return self;
}

- (void)layoutSubviews {
    self.leftImage.frame = CGRectMake(5, 5, self.frame.size.width / 5, self.frame.size.height - 10);
    self.titleLabel.frame = CGRectMake(self.leftImage.right + 5, 5, self.width - self.leftImage.width - 10, self.leftImage.height / 3);
    self.detailLabel.frame = CGRectMake(self.titleLabel.left, self.titleLabel.bottom, self.titleLabel.width, self.leftImage.height - self.titleLabel.height);
//    self.numLabel.frame = CGRectMake(self.width - 30, self.height - 10, 30, 10);
    [self selfAdaptLabel];
    
}

- (void)setNewsSecModel:(NewSecModel *)newsSecModel {
    if (_newsSecModel != newsSecModel) {
        [_newsSecModel release];
        _newsSecModel = [newsSecModel retain];
    }
    [self.leftImage sd_setImageWithURL:[NSURL URLWithString:newsSecModel.img]];
    self.titleLabel.text = newsSecModel.title;
    self.detailLabel.text = newsSecModel.digest;
    
    
    
    
    /**/
    NSString *str = [NSString stringWithFormat:@"%@人阅读", newsSecModel.replyCount];
    self.numLabel.text = str;
//    NSLog(@"%@", str);
    
    
    
    
    

}

- (UIImageView *)leftImage {
    if (!_leftImage) {
        self.leftImage = [[UIImageView alloc] initWithFrame:CGRectZero];
    }
    return _leftImage;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    }
    return _titleLabel;
}

- (UILabel *)detailLabel {
    if (!_detailLabel) {
        self.detailLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _detailLabel.font = [UIFont systemFontOfSize:13];
        _detailLabel.numberOfLines = 0;
    }
    return _detailLabel;
}

//自适应宽度label;

- (UILabel *)numLabel {
    if (!_numLabel) {
        self.numLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _numLabel.font = [UIFont systemFontOfSize:11];
    }
    return _numLabel;
}

- (void)selfAdaptLabel {
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:11]};
    CGRect rect = [self.numLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 10) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.numLabel.frame = CGRectMake(self.frame.size.width - rect.size.width , self.height - 10, rect.size.width, 10);
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
